//
// Created by bxw57 on 2024/6/16.
//

#ifndef MEASURE_TIME_HPP
#define MEASURE_TIME_HPP

#include <chrono>
#include <functional>

// 计时函数模板
template<typename Func, typename... Args>
auto measureTime(Func func, Args&&... args) {
    // 开始计时
    auto start = std::chrono::steady_clock::now();

    // 调用函数并传入参数
    std::invoke(func, std::forward<Args>(args)...);

    // 结束计时
    auto end = std::chrono::steady_clock::now();

    // 计算耗时，单位为毫秒（ms）
    auto diff = end - start;
    return std::chrono::duration <double, std::milli> (diff).count();
}

#endif // MEASURE_TIME_HPP

